//！封装分类数据业务
import { useCategoryAPI } from '@/stores/reclassify'
import { onBeforeRouteUpdate, useRoute } from 'vue-router'
import { onMounted } from '@vue/runtime-core'

export function useCategory() {
    const route = useRoute()
    onMounted(() => {
        useCategoryAPI().categoryAPI(route.params.id)
    })
    //！希望路由变化时候，useCategoryAPI()请求重新发送
    onBeforeRouteUpdate((to) => {
        //!存在问题：使用最新的路由参数请求最新的分类数据
        console.log(to);
        useCategoryAPI().categoryAPI(to.params.id)
    })
    return {
        useCategoryAPI
    }
}